package cn.xorange.commons.system.mapper.system;

import cn.xorange.commons.data.core.mapper.MBaseMapper;
import cn.xorange.commons.system.entity.system.SysRole;
import cn.xorange.commons.system.entity.system.SysRoleOrg;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @author : yangjian
 * @date : 2022/2/22
 */
@Mapper
public interface SysRoleMapper extends MBaseMapper<SysRole> {

    List<SysRole> selectRoleList(@Param(value = "isAdmin") boolean isAdmin,
                                      @Param(value = "userId") Long userId,
                                      @Param(value = "role") SysRole role);

    int checkRoleNameUnique(SysRole role);

    int checkRoleKeyUnique(SysRole role);

    @Select("<script> select group_concat(distinct role_name separator ',') as role from  sys_role where role_key in " +
            "<foreach item = 'key' collection = 'roleKeys' separator=',' open='(' close=')'>" +
            "#{key}" +
            "</foreach></script>")
    String selectRoleNames(@Param("roleKeys") Set<String> roleKeys);
}
